﻿//Global Variables
var map;
var markersArray = [];

function initialize() {
    var myLatLng = new google.maps.LatLng(10.060727, -84.43785);
    var myOptions = {
        center: myLatLng,
        zoom: 12,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    geocoder = new google.maps.Geocoder();
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    //Listener on Click
    google.maps.event.addListener(map, "rightclick", function (event) {       
        myLatLng = new google.maps.LatLng(event.latLng.lat(), event.latLng.lng());
       
        addMarker(null, myLatLng, 'Titulo');
        
    });

}

function addMarker(image, position, title) {    
    var marker;

    if (image == null) {
        marker = new google.maps.Marker({ map: map, position: position, title: title });
    }
    else {
        marker = new google.maps.Marker({ map: map, icon: image, position: position, title: title });
    }
    markersArray.push(marker);
}

// Deletes all markers in the array by removing references to them
function deleteOverlays() {
    if (markersArray) {
        for (i in markersArray) {
            markersArray[i].setMap(null);
        }
        markersArray.length = 0;
    }
}